<?php 
session_start();
include "../_init_.php";

$DT = new DataTable(constant('DB_TABLE_CONTACT_INFO'));
$action= isset($_REQUEST["action"])?$_REQUEST["action"]:'';
switch($action)
{
	case 'edit':
		$info = $DT->get($_REQUEST['id']);
	break;
	case 'delete':
		//remove log
		$dtReplyLog = new DataTable(constant('DB_TABLE_CONTACT_REPLY'));
		$condition = sprintf("`contact_id`=%d",$_REQUEST['id']);
		$dtReplyLog->removeByCondition($condition);
		
		$DT->remove($_REQUEST['id']);
	break;
}


$condition = "1 = 1 ";
if(isset($_REQUEST['sText']) && strlen($_REQUEST['sText']) > 0)
{
	$condition .= ' AND (';
	$condition .= sprintf("`title` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= sprintf(" OR `address` like '%%%s%%'",mysql_real_escape_string($_REQUEST['sText']));
	$condition .= ')';
}
$totalCount = $DT->get_count($condition);

$pagesize = isset($_REQUEST['pagesize']) && intval($_REQUEST['pagesize']) > 0?$_REQUEST['pagesize']:10;
$pagenumber = isset($_REQUEST['pagenumber']) && intval($_REQUEST['pagenumber']) > 0?$_REQUEST['pagenumber']:1;
$pagecount = ceil($totalCount/$pagesize);

$offset = ($pagenumber - 1)*$pagesize;
$orderby = array('-create_time');
$data_list = $DT->get_list($condition,$orderby,$pagesize,$offset);


?>



<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>網站管理系統</title>


<LINK REL="stylesheet" HREF="css/style.css" TYPE="text/css">
<LINK REL="stylesheet" HREF="css/main.css" TYPE="text/css">
<script src="js/FancyZoom.js" language="JavaScript" type="text/javascript"></script>
<script src="js/FancyZoomHTML.js" language="JavaScript" type="text/javascript"></script>
<body onLoad="setupZoom();">

<script src="../js/jquery-ui-1.7.3.custom/js/jquery-1.3.2.min.js" language="JavaScript" type="text/javascript"></script>
<script src="../js/jquery.pager.js"></script>
<link href="../css/page.css" rel="stylesheet" type="text/css" /> 
<script language="javascript">

$(function(){
	$(".pager").pager({ pagenumber: <?php echo $pagenumber;?>, pagecount: <?php echo $pagecount;?>, buttonClickCallback: function(pageclickednumber){
			<?php if(isset($_REQUEST['sText']) && strlen($_REQUEST['sText']) > 0):?>
			document.location='?sText=<?php echo urlencode($_REQUEST['sText']);?>&pagenumber='+pageclickednumber;
			<?php else:?>
			document.location='?pagenumber='+pageclickednumber;
			<?php endif;?>
			
     } }); 
});

function ConfirmDel()
{
   if(confirm("確定要刪除選擇的項目嗎？一旦刪除將不能恢複！"))
     return true;
   else
     return false;	 
}

</script>

<table width="98%" border="0" class="table2">
  <tr>
    <td>聯絡我們 - <a href="admin_contactus_list.php">查看聯絡我們</a></td>
  </tr>
</table>
<?php if($error_message):?>
<div class="error_message"><?php echo $error_message;?></div>
<?php endif;?>
<?php if($sucess_message):?>
<div class="success_message"><?php echo $sucess_message;?></div>
<?php endif;?>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td align="center" valign="top">
      <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
        <tr  class="tr_southidc">          
            <td bgcolor="#B0DAFF">
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="2" bordercolor="#0000FF">
                <tr bgcolor="#E4F2FF"> 
                 <td width="5%" height="25"  bgcolor="#D9EDFF"> 
                  <div align="center">姓名</div></td>
                  <td width="10%" height="25"  bgcolor="#D9EDFF"> 
                  <div align="center">所在地區</div></td>
                  <td width="10%" bgcolor="#D9EDFF"> 
                  <div align="center">地址</div></td>
                  <td width="10%" bgcolor="#D9EDFF"> 
                  <div align="center">郵遞區號</div></td>
                  <td width="10%" bgcolor="#D9EDFF"> 
                  <div align="center">E-mail</div></td>
                  <td width="8%" bgcolor="#D9EDFF"> 
                  <div align="center">查看</div></td>
                  <td width="5%" bgcolor="#D9EDFF"> 
                  <div align="center">刪除</div></td>
                </tr>
<?php 
	foreach($data_list as $row):
	?>
 <tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#E4F2FF'" onMouseOut="this.style.backgroundColor=''"> 
 				<td height="22"> 
                  <div align="center"><?php echo $row['textfield'];?></div></td>
                 
                  <td height="22"> 
                  <div align="center"><?php echo $row['textfield2'];?></div></td>
                  <td> 
                  <div align="center"><?php echo $row['textfield3'];?></div></td>
                  <td> 
                  <div align="center"><?php echo $row['textfield4'];?></div></td>
                  <td> 
                  <div align="center"><?php echo $row['textfield5'];?></div></td>
                  <td> 
                    <div align="center">
                  <a href='contactus_view.php?id=<?php echo $row['id'];?>'>查看</a>                    </div></td>
                  <td> 
                    <div align="center">
				  <a href="?id=<?php echo $row['id'];?>&action=delete" onClick="return ConfirmDel();">刪除</a>                    </div></td>
                </tr>
<?php endforeach;?>
          </table></td>         
        </tr>
       
      </table>
      <div class="pager"></div>
    </td>
  </tr>
</table>

<?php  include("foot.php");?>